<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('实体用况列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>接口名称：</label>
                                <input type="text" name="interfaceName"/>
                            </li>
                            <li>
                                <label>接口地址：</label>
                                <input type="text" name="interfaceUrl2"/>
                            </li>
                            <li>
                                <label>前后类型：</label>
                                <select name="fbType" th:with="type=${@dict.getType('fbType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>操作类型：</label>
                                <select name="optType" th:with="type=${@dict.getType('optType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>接口类型：</label>
                                <select name="interfaceType" th:with="type=${@dict.getType('interfaceType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>风险接口：</label>
                                <select name="isRisk" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>归属服务：</label>
                                <select name="appType" th:with="type=${@dict.getType('appType')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>归属域：</label>
                                <select name="domainId" id="domainId">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${domainInfoList}" th:text="${dict.domainName}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>归属域对象</label>
                                <select name="domainObjectId" id="domainObjectId">
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <label>是否被使用</label>
                                <select name="isUse" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否边界：</label>
                                <select name="isBoundary" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否公共：</label>
                                <select name="isCommon" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否平台：</label>
                                <select name="isPlatform" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否管理：</label>
                                <select name="isManage" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否分支：</label>
                                <select name="isBranch" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>特殊接口：</label>
                                <select name="specialInterface" th:with="type=${@dict.getType('specialInterface')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>生命周期：</label>
                                <select name="lifeCycle" th:with="type=${@dict.getType('lifeCycle')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>设计状态：</label>
                                <select name="preLifeCycle" th:with="type=${@dict.getType('preLifeCycle')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>异常状态：</label>
                                <select name="errorStatus" th:with="type=${@dict.getType('errorStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>接口版本：</label>
                                <select name="productId">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${productInfoList}" th:text="${dict.productName}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>字段模式：</label>
                                <select name="fieldModel" id="fieldModel">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${fieldModelList}" th:text="${dict.modelName}" th:value="${dict.modelEnName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>中文别名：</label>
                                <select name="aliasZhName" id="aliasZhName">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${aliasZhNameList}" th:text="${dict.modelName}" th:value="${dict.modelEnName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>英文别名：</label>
                                <select name="aliasEnName" id="aliasEnName">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${aliasEnNameList}" th:text="${dict.modelName}" th:value="${dict.modelEnName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>其它模式：</label>
                                <select name="otherModel" id="otherModel" th:with="type=${@dict.getType('fieldOtherModel')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>出参判空：</label>
                                <select name="isAllowEmptyModel" id="isAllowEmptyModel" th:with="type=${@dict.getType('isAllowEmpty')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>接口模式：</label>
                                <select name="interfaceModel" id="interfaceModel" th:with="type=${@dict.getType('virtualUsageModel')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px !important;">出参判空（接口）：</label>
                                <select name="interfaceAllowEmptyModel" id="interfaceAllowEmptyModel" th:with="type=${@dict.getType('isAllowEmpty')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>自定义输入（手动）</label>
                                <select name="selfFieldModel" id="selfFieldModel">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${selfFieldModelList}" th:text="${dict.modelName}" th:value="${dict.modelEnName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>自定义输入（选择）</label>
                                <select name="dictCategory" id="dictCategory" >
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${dictCategoryList}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                                <select name="dictType" id="dictType">
                                </select>
                                <select name="dictValue" id="dictValue">
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="interface:interface:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="interface:interface:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="interface:interface:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="interface:interface:export">
                    <i class="fa fa-download"></i> 导出mock数据
                </a>
                <a class="btn btn-warning" onclick="batchUpdate()" shiro:hasPermission="interface:interface:create">
                    <i class="fa fa-download"></i> 批量生成代码
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="text-nowrap table-bordered"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('interface:interface:edit')}]];
        var setEnd = [[${@permission.hasPermi('interface:interface:setEnd')}]];
        var removeFlag = [[${@permission.hasPermi('interface:interface:remove')}]];
        var fbTypeDatas = [[${@dict.getType('fbType')}]];
        var optTypeDatas = [[${@dict.getType('optType')}]];
        var interfaceTypeDatas = [[${@dict.getType('interfaceType')}]];
        var isPageDatas = [[${@dict.getType('sys_yes_no')}]];
        var appTypeDatas = [[${@dict.getType('appType')}]];
        var statusDatas = [[${@dict.getType('status')}]];
        var prefix = ctx + "interface/interface";

        function batchUpdate() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            var url = prefix + "/batchUpdate";
            var data = {};
            $.operate.submit(url, "post", "json", data);
        }

        function detail(id, fbType) {
            $.operate.addTab2("接口详情", prefix + "/bffDetail/" + id);
        }

        function edit(id, fbType) {
            $.operate.addTab2("接口编辑", prefix + "/editInterface/" + id);
            // if (fbType == '1') {
            //     $.operate.addTab2("接口编辑", prefix + "/editDubboNew/" + id);
            // } else {
            //     $.operate.addTab2("接口编辑", prefix + "/bffEdit/" + id);
            // }
        }

        function reset() {
            $("#fieldModel").select2("val", [""]);
            $("#selfFieldModel").select2("val", [""]);
            $("#aliasZhName").select2("val", [""]);
            $("#aliasEnName").select2("val", [""]);
            $("#interfaceModel").select2("val", [""]);
            $("#otherModel").select2("val", [""]);
            $("#isAllowEmptyModel").select2("val", [""]);
            $("#interfaceAllowEmptyModel").select2("val", [""]);
            $("#dictCategory").select2("val", [""]);
            $("#dictType").select2("val", [""]);
            $("#dictValue").select2("val", [""]);
            $.form.reset();
        }

        $(function() {
            $("#fieldModel").select2();
            $("#selfFieldModel").select2();
            $("#aliasZhName").select2();
            $("#aliasEnName").select2();
            $("#interfaceModel").select2();
            $("#otherModel").select2();
            $("#isAllowEmptyModel").select2();
            $("#interfaceAllowEmptyModel").select2();
            $("#dictCategory").select2();
            $("#dictType").select2();
            $("#dictValue").select2();
            bindDictCategoryEvent();
            bindDictTypeEvent();
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "实体用况",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'interfaceName',
                    title: '接口名称',
                    formatter: function(value, row, index) {
                        return "<span title='"+row.interfaceDescription+"'>"+value+"</span>";
                    }
                },
                // {
                //     field: 'interfaceDescription',
                //     title: '接口描述'
                // },
                {
                    field: 'interfaceUrl',
                    title: '接口地址'
                },
                {
                    field: 'fbType',
                    title: '前后类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(fbTypeDatas, value);
                    }
                },
                {
                    field: 'optType',
                    title: '操作类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(optTypeDatas, value);
                    }
                },
                {
                    field: 'interfaceType',
                    title: '接口类型',
                    formatter: function(value, row, index) {
                        if (row.fbType == 2) {
                            return $.table.selectDictLabel(interfaceTypeDatas, value);
                        }
                        return "";
                    }
                },
                {
                    field: 'isRisk',
                    title: '风险接口',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPageDatas, value);
                    }
                },
                {
                    field: 'isPage',
                    title: '是否分页',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPageDatas, value);
                    }
                },
                {
                    field: 'appType',
                    title: '归属服务',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(appTypeDatas, value);
                    }
                },
                {
                    field: 'domainName',
                    title: '归属域'
                },
                {
                    field: 'objectName',
                    title: '归属域对象'
                },
                {
                    field: 'nonFunctionalRequirements',
                    title: '非功能需求'
                },
                    {
                        field: 'status',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(statusDatas, value);
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\', '+row.fbType+')"><i class="fa fa-search"></i>详情</a> ');
                        if (row.lifeCycle != '9') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\', '+row.fbType+')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + setEnd + '" href="javascript:void(0)" onclick="end(\'' + row.id + '\', '+row.fbType+')"><i class="fa fa-edit"></i>封板</a> ');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs ' + setEnd + '" href="javascript:void(0)" onclick="cancelEnd(\'' + row.id + '\', '+row.fbType+')"><i class="fa fa-edit"></i>取消封板</a> ');
                        }
                        if (row.fbType != '2') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="usedInterfaceList(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看调用接口</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        // var more = [];
                        // more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='editParam(" + row.id + ", "+row.interfaceType+")'><i class='fa fa-edit'></i>设置参数</a> ");
                        // more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='tableList(" + row.id + ")'><i class='fa fa-user'></i>关联表</a> ");
                        // if (row.fbType == '2') {
                        //     more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)'' onclick='virtualUsage(" + row.id + ")'><i class='fa fa-edit'></i>虚拟用况</a> ");
                        //     more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='usageList(" + row.id + ")'><i class='fa fa-user'></i>关联用况</a> ");
                        //     more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='businessSystemList(" + row.id + ")'><i class='fa fa-user'></i>关联业务系统</a> ");
                        //     more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='productVersionList(" + row.id + ")'><i class='fa fa-user'></i>关联项目版本</a> ");
                        // }
                        // actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

            $("body").on('change', '#domainId', function () {
                var id = $(this).val();
                var config = {
                    url: ctx + "domainInfo/domainInfo/domainObjectList?id="+id,
                    type: "POST",
                    dataType: "json",
                    data: null,
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                    },
                    success: function(result) {
                        $.modal.closeLoading();
                        $("#domainObjectId").empty();
                        if (result.data && result.data.length > 0) {
                            $("#domainObjectId").append("<option value=''>所有</option>");
                            for (var i=0; i<result.data.length; i++) {
                                $("#domainObjectId").append("<option value='"+result.data[i].id+"'>"+result.data[i].objectName+"</option>");
                            }
                        }
                    }
                };
                $.ajax(config);
            })
        });

        function end(id, fbType) {
            $.modal.confirm("确认封板接口?", function() {
                var url = prefix + "/end";
                var data = { "id": id };
                $.operate.submit(url, "post", "json", data);
            });
        }
        function cancelEnd(id, fbType) {
            $.modal.confirm("确认取消封板接口?", function() {
                var url = prefix + "/cancelEnd";
                var data = { "id": id };
                $.operate.submit(url, "post", "json", data);
            });
        }

        function virtualUsage(id) {
            table.set();
            $.modal.open("设置虚拟用况", prefix + "/virtualUsage/" + id, $(window).width());
        }
        function editParam(id, interfaceType) {
            table.set();
            $.modal.openTab("设置实体用况参数", prefix + "/setParam?id=" + id + "&interfaceType=" + interfaceType, $(window).width());
        }

        function tableList(id) {
            var options = {
                title: "关联表详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/tableList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function usageList(id) {
            var options = {
                title: "关联用况详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/usageList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function usedInterfaceList(id) {
            var options = {
                title: "查看调用接口",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/usedInterfaceList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function businessSystemList(id) {
            var options = {
                title: "关联业务系统详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/businessSystemList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function productVersionList(id) {
            var options = {
                title: "关联产品版本详细",
                width: $(window).width() - 50,
                height: $(window).height() - 50,
                url: prefix + "/productVersionList?id="+id,
                skin: 'layui-layer-gray',
                btn: ['关闭'],
                yes: function (index, layero) {
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }


        function bindDictCategoryEvent() {
            $('#dictCategory').on('select2:select', function (e) {
                var value = $('#dictCategory').select2('val');
                $("#dictType").empty();
                $("#dictValue").empty();
                var url = ctx + "frontInterfaceFieldSource/frontInterfaceFieldSource/getDictListByCategory?category=" + value;
                var config = {
                    url: url,
                    type: "get",
                    dataType: "json",
                    data: null,
                    success: function (result) {
                        var data = result.data;
                        if (data) {
                            $("#dictType").append("<option value=''>所有</option>");
                            for (var i = 0; i < data.length; i++) {
                                $("#dictType").append("<option value='" + data[i].dictType + "'>" + data[i].dictName + "</option>");
                            }
                            queryDictValue(data[0].dictType);
                            //bindDictTypeEvent();
                        }
                    }
                };
                $.ajax(config);

            });
        }

        function bindDictTypeEvent() {
            $('#dictType').on('select2:select', function (e) {
                var value = $('#dictType').select2('val');

                queryDictValue(value);
            });
        }

        function queryDictValue(value) {
            $("#dictValue").empty();
            var url = ctx + "frontInterfaceFieldSource/frontInterfaceFieldSource/queryDict?dictType=" + value;
            var config = {
                url: url,
                type: "post",
                dataType: "json",
                data: null,
                success: function (result) {
                    var data = result.data;
                    if (data) {
                        $("#dictValue").append("<option value=''>所有</option>");
                        for (var i = 0; i < data.length; i++) {
                            $("#dictValue").append("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>");
                        }
                    }
                }
            };
            $.ajax(config);
        }
    </script>
</body>
</html>